import java.util.ArrayList;
import java.util.List;


public class Bank {
	
	 List<Account> list = new ArrayList<Account>();

	 


	public Account kh(int card,int id,String mm,String mz,String sfzh,String yx,double ck,double xyed){

		if (card==1) {
			list.add(new SavingAccount(id,mm,mz,sfzh,yx,ck));
		}else if (card==2) {
			list.add(new CreditAccount(id,mm,mz,sfzh,yx,ck,xyed));
		}
		System.out.println("当前账户用户量："+list.size());
		return null;
	
	}

	public boolean dl(int id,String mm){

		for (int i = 0; i < list.size(); i++) {
			Account acc=list.get(i);
			if (id==acc.getId()) {
				if (mm.equals(acc.getPassword())) {
					System.out.println("登陆成功");
					System.out.println(list.toString());
					
					return true;
				}
			break;
			}
			
		}
		System.out.println("错误");
		return false;	
	}

	public Account ck(int id,double ck){
		
		for (int i = 0; i < list.size(); i++) {
			Account acc=list.get(i);
			if (acc.getId()==id) {			
				acc.deposit(ck);			
				System.out.println(list.toString());
				return acc;
			}
			
		}
		return null;
	}

	public Account qk(int id,double qk){
		for (int i = 0; i < list.size(); i++) {
		Account acc = list.get(i);

			if (acc.getId()==id) {				
				if (acc instanceof CreditAccount) {
					CreditAccount cat=(CreditAccount) list.get(i);
					cat.withdraw(qk);
					System.out.println(list.toString());
				}else{
					acc.withdraw(qk);
					System.out.println(list.toString());					
				}

				return acc;
				
			}
			
		}
		return null;
		
	}
		
	public Account xyk(int id ,double xyed){
			for (int i = 0; i < list.size(); i++) {
				
				if(list.get(i).getId()==id){
					if (list.get(i) instanceof CreditAccount) {
						CreditAccount cat=(CreditAccount) list.get(i);
						cat.setCeiling(xyed);
						System.out.println("已更改");
					}else {
						System.out.println("不是信用账户,不能更改");
					}
				}

				
			}
			return null;	
	
	}
	
	
	public void tongji(){
		double sun=0;
		double touzhisun=0;
		
		for (int i = 0; i < list.size(); i++) {
			Account acc = list.get(i);
			
			sun+=acc.getBalance();
			if (acc instanceof CreditAccount) {
				CreditAccount cat=(CreditAccount) acc;		
				touzhisun+=cat.getCeiling();
			}
			
				
		}
		System.out.println("所有账户余额总数："+sun);
		System.out.println("所有账户透支总数："+touzhisun);
	}
	
	
	

}